const http = require("http");
const url = require("url");
const fs = require("fs");
const server = http.createServer((req, res) => {
  let query = url.parse(req.url, true).query;
  if (typeof query.username !== "undefined") {
    try {
      var arr = [];
      var newArr = arr.push(query);
      fs.writeFileSync("./data.json", JSON.stringify(newArr));
      res.write("success");
    } catch (err) {
      console.log(err);
      res.write("error");
    }
  }
  res.end();
});

server.listen(8989);
